#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
struct c{
    ll l,r;
};
c a[100005];
bool out[100005];
ll f1[1000005];
ll f2[1000005];
bool operator <(c n,c m)
{
    return n.r<m.r;
}
ll chu(ll n,ll m)
{
    if(n%m==0)
    {
        return n/m-1;
    }
    else
    {
        return n/m;
    }
}
int main()
{
    freopen("detect.in","r",stdin);
    freopen("detect.out","w",stdout);
    ll t;
    cin>>t;
    while(t--)
    {
        memset(a,0,sizeof(a));
        memset(out,0,sizeof(out));
        memset(f1,0,sizeof(f1));
        memset(f2,0,sizeof(f2));
        ll n,m,le,vx,ans1=0,ans2;
        cin>>n>>m>>le>>vx;
        ans2=m;
        for(ll i=1;i<=n;i++)
        {
            ll wz,csd,jsd;
            cin>>wz>>csd>>jsd;
            if(jsd!=0)
            {
                if(jsd>0)
                {
                    a[i].l=wz+ll((vx*vx-csd*csd)/(jsd*2ll)+1ll);
                    a[i].r=le;
                    if(a[i].l>le)
                    {
                        a[i].r=0;
                        a[i].l=0;
                        out[i]=1;
                    }
                }
                else
                {
                    a[i].l=wz;
                    a[i].r=wz+max(-1ll,chu((vx+csd)*(vx-csd),jsd*2ll));
                    if(a[i].r==a[i].l-1)
                    {
                        a[i].r=0;
                        a[i].l=0;
                        out[i]=1;
                    }
                }
            }
            else
            {
                if(csd>vx)
                {
                    a[i].l=wz;
                    a[i].r=le;
                }
            }
        }
        for(ll i=1;i<=m;i++)
        {
            ll x;
            cin>>x;
            if(x<0)
            {
                break;
            }
            f1[x]=1;
            f2[x]=1;
        }
        for(ll i=1;i<=1000000;i++)
        {
            if(f1[i]==0)
            {
                f1[i]=f1[i-1];
            }
            else
            {
                f1[i]=i;
            }
        }
        f2[1000001]=LONG_LONG_MAX;
        for(ll i=1000000;i>=1;i--)
        {
            if(f2[i]==0)
            {
                f2[i]=f2[i+1];
            }
            else
            {
                f2[i]=i;
            }
        }
        for(ll i=1;i<=n;i++)
        {
            if(f1[a[i].r]>=f2[a[i].l]&&f1[a[i].r]!=0&&!out[i])
            {
                ans1++;
            }
            else
            {
                a[i].l=0;
                a[i].r=0;
            }
        }
        sort(a+1,a+n+1);
        //for(ll i=1;i<=n;i++)
        //{
            //cout<<a[i].l<<" "<<a[i].r<<"\n";
        //}
        ll mxr=0;
        ll qs=1;
        for(;qs<=n;qs++)
        {
            if(a[qs].r!=0)
            {
                mxr=a[qs].r;
                ans2--;
                break;
            }
        }
        for(ll i=qs;i<=n;i++)
        {
            //cout<<f1[mxr]<<" "<<f2[a[i].l]<<"\n";
            if(f2[a[i].l]>f1[mxr])
            {
                ans2--;
                mxr=a[i].r;
            }
        }
        cout<<ans1<<" "<<ans2<<"\n";
    }
    return 0;
}
